package com.wf.day_0603.test3;

import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author mpk
 * @since 2024/6/3 17:33:34
 */

//练习3.定义一个People数组，将People数组中的重复对象剔除
public class Demo {
    public static void main(String[] args) {


        People[] p = {

                new People("John", 29),
                new People("John", 29),
                new People("yuekai", 15),
                new People("honglian", 16),

        };
        System.out.println("---去重前---");
        System.out.println(Arrays.toString(p));

        Set<People> collect = Stream.of(p)

                .collect(Collectors.toSet());

        Object[] array = collect.toArray();

        p = Arrays.copyOf(array, array.length, People[].class);

        System.out.println("---去重后---");

        System.out.println(Arrays.toString(p));


    }

}
